const express = require('express');
const axios = require('axios');
const app = express();


const cors = require('cors');
const corsOptions = {
    origin: 'http://192.168.6.66',
    allowedHeaders: ['Content-Type']
};
app.use(cors(corsOptions));
app.use(express.json());

// 代理请求到DeepSeek
app.post('/api/chat', async (req, res) => {
    console.log(JSON.stringify(req.body.messages))
    try {
        const response = await axios.post(
            'https://api.deepseek.com/chat/completions',
            {
                model: "deepseek-reasoner",
                messages: req.body.messages,
                temperature: 0.3
            },
            {
                headers: {
                    'Authorization': `Bearer sk-03eecd4d1ff64b1db476e14d592c8824`,
                    'Content-Type': 'application/json'
                }
            }
        );
        // res.json(response.data);

        res.json({ choices: [{ message: { content: '你好' } }] });
        // data.choices[0].message.content;
    } catch (error) {
        // console.error(error);
        // res.status(500).json({ error: 'API请求失败' });
        const content = '接口都买不起，有啥好聊的？'
        res.json({ choices: [{ message: { content } }] });
    }
});

app.listen(3000, () => {
    console.log('代理服务器已启动，端口号：3000');
});



// curl -X POST https://api.deepseek.com/v1/chat/completions -H "Authorization: Bearer 'sk-b258b2df9fe6462e9778f7b9a82a0b1c'" -H "Content-Type: application/json" -d "{'model': 'deepseek-chat', 'messages': [{'role': 'user', 'content': 'Hello'}], 'temperature': 0.3}"